import AdminRouter from "./AdminRouter"
//@ts-ignore 载入全部页面
const PageComponents: { [key: string]: any } = import.meta.glob(`@/apps/admin/view/**/*.page.vue`)

/**
 * 载入布局组件
 */
import LayoutDefault from "@/apps/admin/components/Layout/Main.vue";

import PageEmpty from "@/apps/admin/components/Page/PageEmpty.vue"//空页面组件
import PageNotFound from "@/apps/admin/components/Page/PageNotFound.vue"//404页面组件
/**
 * 默认路由
 */
const DefaultRoutes: Array<any> = [
    {//默认后台布局
        key: "admin-layout",
        name: "admin-layout",
        component: LayoutDefault,
        children: [
            {
                path: '/empty',
                name: "empty",
                component: PageEmpty,
                meta: {
                    local: true,
                    title: "错误提醒",
                    tourist: false,//游客可以访问
                    icon: '',
                    auth: null,
                    breadcrumb: ['首页', '错误提醒']//面包屑
                }
            },
            {
                path: '/not-found',
                name: "not-found",
                component: PageNotFound,
                meta: {
                    local: true,
                    title: "错误提醒",
                    tourist: false,//游客可以访问
                    icon: '',
                    auth: null,
                    breadcrumb: ['首页', '404 Not Found']//面包屑
                }
            }
        ]
    },
    {//空布局
        key: "empty-layout",
        name: "empty-layout",
        children: [
            {
                path: '/login/index',
                name: "/login/index",
                component: PageComponents['/src/apps/admin/view/login/index.page.vue'],
                meta: {
                    local: true,
                    title: "登录",
                    tourist: true,//游客可以访问
                    icon: '',
                    auth: [],
                    breadcrumb: ['登录']//面包屑
                }
            }
        ]
    }
]

let pages: { [key: string]: any } = {}
/**
 * 全部注册默认页面路由
 */
for (let path in PageComponents) {
    let router = path.replace(/(\/src\/apps\/admin\/view|.page.vue)/g, '')
    DefaultRoutes[0].children.push({
        path: router,
        name: router,
        component: PageComponents[path],
        meta: {
            local: false
        }
    })
    pages[router] = PageComponents[path]
}

/**
 * 创建路由实例
 */
const routers = new AdminRouter(DefaultRoutes, pages)

/**
 * 导出路由实例
 */
export default routers.createRouter();